<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/common/taglibs.jsp"%>
    <%@ include file="/common/cssAndjs.jsp"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>物料列表</title>
	 
	 <script type="text/javascript">
	 var materialStatus =${materialStatus};
	 
	 function unitformatter(value, rowData, rowIndex) {
		    for (var i = 0; i < materialStatus.length; i++) {
		        if (materialStatus[i].code == value) {
		            return materialStatus[i].name;
		        }
		    }
		}
	 
	 $(function(){
		 var editRow = undefined;
			$('#materialList').datagrid({
				
				iconCls:'icon-save',
				fitColumns:true,
				nowrap: true,
				fit:true,
				triped: true,
				singleSelect: true,
				collapsible:true,
				url:'${ctx}/material/getMaterialList',
				sortName: 'id',
				sortOrder: 'desc',
				remoteSort: false,
				idField:'id',
				frozenColumns:[[
	                {field:'id',checkbox:true}
				]],
				columns:[[
				          {field:'mname',title:'物料名',width:100},
				          {field:'unit',title:'单位',width:100},
				          {field:'price',title:'单价',width:100},
				          {field:'createDate',title:'创建日期',width:100},
				          {field:'updateDate',title:'修改日期',width:100},
				          {field:'status',title:'状态',formatter: unitformatter,width:200,align:'left',editor: { type: 'combobox', options: { data: materialStatus, valueField: "code", textField: "name" } }}
				]],
				pagination:true,
				rownumbers:true,
				toolbar:"#toolbar",
				onAfterEdit: function (rowIndex, rowData, changes) {
		            editRow = undefined;
		        },
		        onDblClickRow: function (rowIndex, rowData) {
		            if (editRow != undefined) {
		                $("#materialList").datagrid('endEdit', editRow);
		            }
		 
		            if (editRow == undefined) {
		                $("#materialList").datagrid('beginEdit', rowIndex);
		                editRow = rowIndex;
		            }
		        },
		        onClickRow: function (rowIndex, rowData) {
		            if (editRow != undefined) {
		                $("#materialList").datagrid('endEdit', editRow);
		 
		            }
		        }
			});
			var p = $('#materialList').datagrid('getPager');
			$(p).pagination({
				onBeforeRefresh:function(){
					//alert('before refresh');
				}
			});
			
			
		});
	
	 /* 模态方式打开物料录入页面 */
	    function addTab(){
	    	var  iWidth=880; //模态窗口宽度
	    	var  iHeight=280;//模态窗口高度
	    	var iTop=(window.screen.height-iHeight)/2; 
	    	var iLeft=(window.screen.width-iWidth)/2; 

	      var param="";
	      param = "?operWay=1" ;
	      var openStatus = "width=880,height=280,menubar=no,toolbar=no,top="+iTop+",left="+iLeft+",Location=no,scrollbars=no,status=no,modal=yes";
	      
	      window.open("${ctx}/material/materialAddOrEdit"+param, "", openStatus);
	     
	    }
	function editTab(){
		var  iWidth=880; //模态窗口宽度
    	var  iHeight=280;//模态窗口高度
    	var iTop=(window.screen.height-iHeight)/2; 
    	var iLeft=(window.screen.width-iWidth)/2; 
		var param="";
		 var rows = $("#materialList").datagrid("getSelections");
	      if (rows.length == 0) {
	        $.messager.alert("请选择一条信息","提示");
	        return;
	      }
	      var id = rows[0].id;
		param = "?operWay=2&id="+id ;
		var openStatus = "width=880,height=280,menubar=no,toolbar=no,top="+iTop+",left="+iLeft+",Location=no,scrollbars=no,status=no,modal=yes";
		
		window.open("${ctx}/material/materialAddOrEdit"+param, window, openStatus);
		
	    
		
	}
	function viewTab(){
		
	}
	function searchTab(){
		
	}
	
	  /* 刷新DataGrid表单 */
    function refreshGrid(params){
      if(typeof params == "undefined" || params == null){
         params = {};
      }
      $('#materialList').datagrid("options").pageNumber = 1;   
      //分页栏上跳转到第一页   
      $('#materialList').datagrid('getPager').pagination({pageNumber: 1});
      // 刷新DataGrid表单
      $("#materialList").datagrid('reload',params);
      $('#materialList').datagrid('clearSelections');
    }
	$(window).resize(function(){
		$('#materialList').datagrid('resize', {
		width:function(){return document.body.clientWidth;},
		height:function(){return document.body.clientHeight;},
		});
		});
	</script>
	 <style type="text/css">
    html, body{
        margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
    }    
    </style>
	
</head>
<body >
   <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addTab()">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editTab()">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-view" plain="true" onclick="editTab()">New</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-view" plain="true" onclick="editTab()">Destroy</a>
    </div>
          <table  id="materialList" class="easyui-datagrid"  cellpadding="0" cellspacing="0" border="0" ></table>
           
</body>
</html>